const qiniu = require('qiniu');

// 七牛云配置
const config = {
    accessKey: process.env.QINIU_ACCESS_KEY,
    secretKey: process.env.QINIU_SECRET_KEY,
    bucket: process.env.QINIU_BUCKET,
    domain: process.env.QINIU_DOMAIN,
    zone: qiniu.zone.Zone_z1,  // 华东区
    uploadURL: 'https://up.qiniup.com',  // 华东区上传域名
    useHttpsDomain: true,//https
    useCdnDomain: true //cdn加速
};

// 创建上传凭证
const createUploadToken = () => {
    const mac = new qiniu.auth.digest.Mac(config.accessKey, config.secretKey);
    const putPolicy = new qiniu.rs.PutPolicy({
        scope: config.bucket
    });
    return putPolicy.uploadToken(mac);
};

module.exports = {
    config,
    createUploadToken
}; 